﻿using System;
using System.Collections.Generic;
using System.Web;

namespace NFinal.Handler
{
    internal class HandlerFactory : IHttpHandlerFactory
    {
        private IHttpHandler _handler;
        private Type _handlerType;

        internal HandlerFactory(IHttpHandler handler, Type handlerType)
        {
            this._handler = handler;
            this._handlerType = handlerType;
        }

        public IHttpHandler GetHandler(HttpContext context,
                                    string requestType, string url, string pathTranslated)
        {
            if (this._handler == null)
                this._handler = new Handler();

            return this._handler;
        }

        public void ReleaseHandler(IHttpHandler handler)
        {
            // 一个HttpHandler是否能重用，这里就是一个典型的实现方式
            if (!this._handler.IsReusable)
                this._handler = null;
        }
    }
}